package com.tulele.vtool.service.impl;

import com.tulele.vtool.mapper.ArticleTailAdvertInfoMapper;
import com.tulele.vtool.mapper.ArticleTypeInfoMapper;
import com.tulele.vtool.model.ArticleTypeInfo;
import com.tulele.vtool.model.MateriaUserRelateTypeInfo;
import com.tulele.vtool.model.combinedEntity.CombinedArticleTypeAdvertTemplate;
import com.tulele.vtool.service.IArticleTypeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleTypeInfoServiceImpl implements IArticleTypeInfoService {

    @Autowired
    private ArticleTypeInfoMapper articleTypeInfoMapper;

    @Override
    public List<ArticleTypeInfo> getArticleTypeInfo() {
        return articleTypeInfoMapper.queryArticleTypeInfo();
    }

    @Override
    public List<ArticleTypeInfo> getArticleTypeInfoItem() {
        return articleTypeInfoMapper.queryArticleTypeInfoItem();
    }

    @Override
    public String queryDefaultAdvert() {
        return articleTypeInfoMapper.queryDefaultAdvert();
    }

    @Override
    public ArticleTypeInfo getArticleTypeInfoByArticleTypeName(String articleTypeName) {
        return articleTypeInfoMapper.queryArticleTypeInfoByArticleTypeName(articleTypeName);
    }

    @Override
    public List<ArticleTypeInfo> getArticleTypeInfoByIds(List<String> articleTypeIds) {
        return articleTypeInfoMapper.queryArticleTypeInfoByIds(articleTypeIds);
    }

    @Override
    public List<ArticleTypeInfo> selectUserAttentionMaterialType(int userId) {
        return this.articleTypeInfoMapper.selectUserAttentionMaterialType(userId);
    }

    @Override
    public List<ArticleTypeInfo> selectUserAttentionMaterialTypeItem(int userId) {
        return this.articleTypeInfoMapper.selectUserAttentionMaterialTypeItem(userId);
    }

    @Override
    public void addUserAttentionMaterialTypeAndBrand(MateriaUserRelateTypeInfo materiaUserRelateTypeInfo, List<String> articleTypeIdList) {
        //先删除该用户关注的所有分类
        this.articleTypeInfoMapper.delUserAttentionMaterialType(materiaUserRelateTypeInfo.getUserId());
        // 用户关注分类
        articleTypeIdList.forEach(articleTypeId->{
            materiaUserRelateTypeInfo.setArticleTypeId(Integer.valueOf(articleTypeId));
            this.articleTypeInfoMapper.addUserAttentionMaterialType(materiaUserRelateTypeInfo);
        });
    }

    @Override
    public ArticleTypeInfo selectBrandNameAndBrandHeadByTypeId(Integer articleTypeId) {
        return this.articleTypeInfoMapper.selectBrandNameAndBrandHeadByTypeId(articleTypeId);
    }

    @Override
    public String getTypeInfoByTypeId(Integer typeId) {
        return articleTypeInfoMapper.getTypeInfoByTypeId(typeId);
    }

    @Override
    public String getDefaultAdvertInfo(Integer typeId) {
        return articleTypeInfoMapper.getDefaultAdvertInfo(typeId);
    }

    @Override
    public List<CombinedArticleTypeAdvertTemplate> getArticleTypeAdvertTemplate(List<Integer> articleTypeIdList) {
        return articleTypeInfoMapper.getArticleTypeAdvertTemplate(articleTypeIdList);
    }

    @Override
    public ArticleTypeInfo getInfoById(Integer articleTypeId) {
        return articleTypeInfoMapper.getInfoById(articleTypeId);
    }
}
